package com.example.yunkafka.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author CHENTAIWEN
 * @create 2022/8/25 13:08
 */
@Slf4j
@Service
public class KafkaConsumerListener {

    /**
     * kafka消息处理类
     *
     */
    public void listen(ConsumerRecord<String, String> consumerRecord) throws Exception {
        try {
            String value = consumerRecord.value();
            Date date = new Date();
            log.error("{}监听Kafka消息：" + value,date);
            // 实际业务处理逻辑
        }catch (Exception e){
            throw new Exception(this.getClass().getName() + "Kafka消息处理异常：" + e);
        }
    }
}